//
//  HandCarAuthenticationController.m
//  NtoccDriverNew
//
//  Created by 张天兴 on 2025/9/19.
//  Copyright © 2025 GCY. All rights reserved.
//

#import "HandCarAuthenticationController.h"
#import "AutherTicationCellTableViewCell.h"
#import "IDCardTitleTextTableViewCell.h"
#import "TZImagePickerController.h"
#import "SelectedImagUpDataImagView.h"
#import "BreakBoundsAuthenticationController.h"
#import "RoadTransportEmptyListView.h"
@interface HandCarAuthenticationController ()<UITableViewDelegate, UITableViewDataSource,TZImagePickerControllerDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>
@property (strong , nonatomic)UITableView *tableView;
@property (nonatomic, strong) UIImagePickerController *imagePickerController;
@property (strong, nonatomic)SelectedImagUpDataImagView *selectedTypeView;
@property (strong, nonatomic) RoadTransportEmptyListView *roadTview;//示列图
@property (strong, nonatomic) NSMutableArray *dataArr;
@property (strong, nonatomic) NSIndexPath *curentIndexPath;
@property (strong,nonatomic) UIButton *commitUpDataButton;

@property (strong,nonatomic) NSString *gccpStr;
@property (strong,nonatomic) NSString *dlyszhStr;
@property (strong,nonatomic) NSString *dlysxkzStr;
@property (strong,nonatomic) NSString *dlysTimeStr;

@property (strong,nonatomic) NSMutableDictionary *gcxszZDic;
@property (strong,nonatomic) NSMutableDictionary *gcxszFDic;
@property (strong,nonatomic) NSMutableDictionary *gcyszDic;



@end

@implementation HandCarAuthenticationController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"挂车认证";
    
    self.view.backgroundColor = BackgroundColor;
    [self newDataArr];
    [self.view addSubview:self.tableView];
    [self.view addSubview:self.commitUpDataButton];
    self.gcxszZDic = [NSMutableDictionary dictionary];
    self.gcxszFDic = [NSMutableDictionary dictionary];
    self.gcyszDic = [NSMutableDictionary dictionary];
    self.dlyszhStr = @"--";
    self.dlysxkzStr = @"--";
    self.dlysTimeStr = @"--";
}
- (void)newDataArr{
    self.dataArr = [@[] mutableCopy];
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setValue:@"挂车行驶证正页上传" forKey:@"title"];
    [dic setValue:@"guachexingshizhengzhengye" forKey:@"defaultImag"];
    [dic setValue:@"" forKey:@"imgURL"];
    [dic setValue:@"0" forKey:@"upType"];
    [dic setValue:@"识别失败(点击重新上传)" forKey:@"falseTitle"];
    [dic setValue:@"曝光严重无法准确识别文字内容" forKey:@"falseCentent"];
    [dic setValue:@"1" forKey:@"isImagType"];
    [dic setValue:@"guachexingshizhengzhengyeshilie" forKey:@"ballbackImag"];
    [self.dataArr addObject:dic];
    NSMutableDictionary *dic1 = [NSMutableDictionary dictionary];
    [dic1 setValue:@"挂车行驶证副页上传" forKey:@"title"];
    [dic1 setValue:@"" forKey:@"imgURL"];
    [dic1 setValue:@"0" forKey:@"upType"];//0没识别之前 1 成功。2 失败
    [dic1 setValue:@"识别失败(点击重新上传)" forKey:@"falseTitle"];
    [dic1 setValue:@"曝光严重无法准确识别文字内容" forKey:@"falseCentent"];
    [dic1 setValue:@"guachexingshizhengfuye" forKey:@"defaultImag"];
    [dic1 setValue:@"1" forKey:@"isImagType"];
    [dic1 setValue:@"guachexingshizhengfuyeshilie" forKey:@"ballbackImag"];

    [self.dataArr addObject:dic1];
    NSMutableDictionary *dic2 = [NSMutableDictionary dictionary];
    [dic2 setValue:@"挂车道路运输证上传" forKey:@"title"];
    [dic2 setValue:@"" forKey:@"imgURL"];
    [dic2 setValue:@"0" forKey:@"upType"];//0没识别之前 1 成功。2 失败
    [dic2 setValue:@"识别失败(点击重新上传)" forKey:@"falseTitle"];
    [dic2 setValue:@"曝光严重无法准确识别文字内容" forKey:@"falseCentent"];
    [dic2 setValue:@"guachedaoluyunshuzhengnianshengpingzhengshipie" forKey:@"defaultImag"];
    [dic2 setValue:@"1" forKey:@"isImagType"];
    [dic2 setValue:@"guachedaoluyunshuzhengnianshengshilie" forKey:@"ballbackImag"];
    [self.dataArr addObject:dic2];
    
    NSMutableDictionary *dic3 = [NSMutableDictionary dictionary];
    [dic3 setValue:@"挂车道路运输证年审凭证上传" forKey:@"title"];
    [dic3 setValue:@"" forKey:@"imgURL"];
    [dic3 setValue:@"0" forKey:@"upType"];//0没识别之前 1 成功。2 失败
    [dic3 setValue:@"识别失败(点击重新上传)" forKey:@"falseTitle"];
    [dic3 setValue:@"曝光严重无法准确识别文字内容" forKey:@"falseCentent"];
    [dic3 setValue:@"guachedaoluyunshuzhengnianshengshilie" forKey:@"defaultImag"];
    [dic3 setValue:@"1" forKey:@"isImagType"];
    [dic3 setValue:@"guachedaoluyunshuzhengshilie" forKey:@"ballbackImag"];
    [self.dataArr addObject:dic3];
}
#pragma mark - UITableViewDelegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dic = self.dataArr[indexPath.row];
    if ([dic[@"isImagType"] isEqualToString:@"1"]) {
        return 258;
    }else{
        return 50;
    }
   
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.001f;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dic = self.dataArr[indexPath.row];
    if ([dic[@"isImagType"] isEqualToString:@"1"]) {
        AutherTicationCellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AutherTicationCellTableViewCell"];
        [cell.upImagButton addTarget:self action:@selector(updataImage:) forControlEvents:(UIControlEventTouchUpInside)];
        [cell.topBakButton addTarget:self action:@selector(updataImage:) forControlEvents:(UIControlEventTouchUpInside)];
        [cell assignmentDic:self.dataArr[indexPath.row]];
        if ([dic[@"title"] isEqualToString:@"道路运输证上传"] || [dic[@"title"] isEqualToString:@"道路运输证年审凭证"]){
            cell.lookImagButton.hidden = NO;
            [cell.lookImagButton addTarget:self action:@selector(lookImagButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
       }else {
           cell.lookImagButton.hidden = YES;
       }
        return cell;
    }else{
        IDCardTitleTextTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"IDCardTitleTextTableViewCell"];
        cell.nameTitleLabel.text = dic[@"title"];
        cell.cententTextLabel.text = dic[@"textContent"];
        return cell;
    }

}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArr.count;
}

#pragma mark - LazyLoad
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.frame = CGRectMake(0, 0, ScreenW, ScreenH - NavHeight - MenuBarHeight  - 50);
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = BackgroundColor;
        
        //注册单元格
        [_tableView registerNib:[UINib nibWithNibName:@"AutherTicationCellTableViewCell" bundle:nil] forCellReuseIdentifier:@"AutherTicationCellTableViewCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"IDCardTitleTextTableViewCell" bundle:nil] forCellReuseIdentifier:@"IDCardTitleTextTableViewCell"];
    }
    
    return _tableView;
}

- (UIButton *)commitUpDataButton{
    if (_commitUpDataButton == nil) {
        self.commitUpDataButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        self.commitUpDataButton.frame = CGRectMake(15, ScreenH - MenuBarHeight - 50 - NavHeight, ScreenW - 30, 50);
        [self.commitUpDataButton addTarget:self action:@selector(commitUpDataButtonAction) forControlEvents:UIControlEventTouchUpInside];
        self.commitUpDataButton.backgroundColor = Theme_ColorValue;
        [self.commitUpDataButton setTitle:@"确认上传审核" forState:(UIControlStateNormal)];
        [self.commitUpDataButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        self.commitUpDataButton.layer.masksToBounds = YES;
        self.commitUpDataButton.layer.cornerRadius = 10;
    }
    return _commitUpDataButton;
}

- (void)commitUpDataButtonAction{
    [self networkingRequest];
}
- (void)networkingRequest{
    NSString * vehicleLicenseOCRFrontStr = [self dicZhuanJsonStr:self.xszZdic];
    NSString * vehicleLicenseOCRBackStr = [self dicZhuanJsonStr:self.xszFdic];
    NSString * newVehicleLicenseOCRBackStr = [self dicZhuanJsonStr:self.xszZXFdic];
    NSString * licensePlateOCRStr  = [self dicZhuanJsonStr:self.ctdic];
    NSString * roadTransportPermitOCRStr = [self dicZhuanJsonStr:self.yszdic];
    NSString * trailerVehicleLicenseOCRFrontStr = [self dicZhuanJsonStr:self.gcxszZDic];
    NSString * trailerVehicleLicenseDeputyPageOCRBackStr = [self dicZhuanJsonStr:self.gcxszFDic];
    NSString * trailerRoadTransportPermitOCRStr = [self dicZhuanJsonStr:self.gcyszDic];
    NSString *vehicleLicenseImg;
    NSString *vehicleLicenseDeputyPageImg;
    NSString *newVehicleLicenseDeputyPageImg;
    NSString *vehicleImg;
    NSString *roadTransportCertificateImg;
    NSString *roadPermitNumberImg;
    NSString *trailerVehicleLicenseImg;
    NSString *trailerVehicleLicenseDeputyPageImg;
    NSString *trailerRoadTransportCertificateImg;
    NSString *trailerAnnualReviewImg;
    for (NSDictionary *dict in self.topDataArr) {
        if ([dict[@"title"] isEqualToString:@"车辆行驶证正页上传"]) {
            vehicleLicenseImg = dict[@"imgURL"];
        }else if ([dict[@"title"] isEqualToString:@"车辆行驶证副页上传"]){
            vehicleLicenseDeputyPageImg = dict[@"imgURL"];
        }else if ([dict[@"title"] isEqualToString:@"车辆行驶证最新到期日期页照片"]){
            newVehicleLicenseDeputyPageImg = dict[@"imgURL"];
        }else if ([dict[@"title"] isEqualToString:@"带有车牌的车头上传"]){
            vehicleImg = dict[@"imgURL"];
        }else if ([dict[@"title"] isEqualToString:@"道路运输证上传"]){
            roadTransportCertificateImg = dict[@"imgURL"];
        }else if ([dict[@"title"] isEqualToString:@"道路运输证年审凭证(非必传)"]){
            roadPermitNumberImg = dict[@"imgURL"];
        }
    }
    for (NSDictionary *dict in self.dataArr) {
        if ([dict[@"title"] isEqualToString:@"挂车行驶证正页上传"]) {
            trailerVehicleLicenseImg = dict[@"imgURL"];
        }else if ([dict[@"title"] isEqualToString:@"挂车行驶证副页上传"]){
            trailerVehicleLicenseDeputyPageImg = dict[@"imgURL"];
        }else if ([dict[@"title"] isEqualToString:@"挂车道路运输证上传"]){
            trailerRoadTransportCertificateImg = dict[@"imgURL"];
        }else if ([dict[@"title"] isEqualToString:@"挂车道路运输证年审凭证上传"]){
            trailerAnnualReviewImg = dict[@"imgURL"];
        }
       
    }
    if (trailerVehicleLicenseOCRFrontStr.length <= 0 || trailerVehicleLicenseImg.length <= 0) {
        [XSInfoView showInfo:@"请正确上传挂车行驶证正页" onView:self.view];
        return;
    }
    if (trailerVehicleLicenseDeputyPageOCRBackStr.length <= 0 ||  trailerVehicleLicenseDeputyPageImg.length <= 0) {
        [XSInfoView showInfo:@"请正确上传挂车行驶证副页" onView:self.view];
        return;
    }
    if (trailerRoadTransportPermitOCRStr.length <= 0 ||  trailerRoadTransportCertificateImg.length <= 0) {
        [XSInfoView showInfo:@"请正确上传挂车道路运输证" onView:self.view];
        return;
    }
//    if (trailerAnnualReviewImg.length <= 0) {
//        [XSInfoView showInfo:@"请正确上传挂车道路运输证年审凭证" onView:self.view];
//        return;
//    }
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setValue:vehicleLicenseOCRFrontStr forKey:@"vehicleLicenseOCRFrontStr"];
    [dic setValue:vehicleLicenseOCRBackStr forKey:@"vehicleLicenseOCRBackStr"];
    [dic setValue:newVehicleLicenseOCRBackStr forKey:@"newVehicleLicenseOCRBackStr"];
    [dic setValue:licensePlateOCRStr forKey:@"licensePlateOCRStr"];
    [dic setValue:roadTransportPermitOCRStr forKey:@"roadTransportPermitOCRStr"];
    [dic setValue:vehicleLicenseImg forKey:@"vehicleLicenseImg"];
    [dic setValue:vehicleLicenseDeputyPageImg forKey:@"vehicleLicenseDeputyPageImg"];
    [dic setValue:newVehicleLicenseDeputyPageImg forKey:@"newVehicleLicenseDeputyPageImg"];
    [dic setValue:vehicleImg forKey:@"vehicleImg"];
    [dic setValue:roadTransportCertificateImg forKey:@"roadTransportCertificateImg"];
    [dic setValue:roadPermitNumberImg forKey:@"roadPermitNumberImg"];
    [dic setValue:trailerVehicleLicenseOCRFrontStr forKey:@"trailerVehicleLicenseOCRFrontStr"];
    [dic setValue:trailerVehicleLicenseDeputyPageOCRBackStr forKey:@"trailerVehicleLicenseDeputyPageOCRBackStr"];
    [dic setValue:trailerRoadTransportPermitOCRStr forKey:@"trailerRoadTransportPermitOCRStr"];
    [dic setValue:trailerVehicleLicenseImg forKey:@"trailerVehicleLicenseImg"];
    [dic setValue:trailerVehicleLicenseDeputyPageImg forKey:@"trailerVehicleLicenseDeputyPageImg"];
    [dic setValue:trailerRoadTransportCertificateImg forKey:@"trailerRoadTransportCertificateImg"];
    [dic setValue:trailerAnnualReviewImg forKey:@"trailerAnnualReviewImg"];
    [dic setValue:[UserDefaultUtil valueForKey:USER_CODE]  forKey:@"teamCode"];
    [dic setValue:self.isChaoStr forKey:@"ifOverQuota"];
    [HTTPManager jsonNetworkRequestWithMethod:@"POST" urlString:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-basic-api",[ReAddressDynamic shared].baseUrl], VEHICLE_TRAILEROCRINFO) withParameter:dic withVC:self netName:@"有挂车图片上传车辆" success:^(id response, NSString *msg) {
        [XSInfoView showInfo:msg onView:self.view.window];
        [self.navigationController popToRootViewControllerAnimated:YES];
        } failure:^(NSInteger code, NSString *msg) {
            
        }];
}
- (void)lookImagButtonAction:(UIButton *)btn{

    CGPoint point = btn.center;//找到btn中心点记录下来
    point = [self.tableView convertPoint:point fromView:btn.superview];
    NSIndexPath* indexpath = [self.tableView indexPathForRowAtPoint:point];
    NSDictionary *dict = self.dataArr[indexpath.row];
    
    if ([dict[@"title"] isEqualToString:@"道路运输证上传"]){
        self.roadTview = [[RoadTransportEmptyListView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, ScreenH) styType:@"0"];
    }else if([dict[@"title"] isEqualToString:@"道路运输证年审凭证"]){
        self.roadTview = [[RoadTransportEmptyListView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, ScreenH) styType:@"1"];
    }
    [self.roadTview.cententButton addTarget:self action:@selector(cententButtonAction) forControlEvents:(UIControlEventTouchUpInside)];
    [[UIApplication sharedApplication].keyWindow addSubview:self.roadTview];
}
- (void)cententButtonAction{
    [self.roadTview removeFromSuperview];
}
- (void)updataImage:(UIButton *)btn{
    WEAKSELF
    CGPoint point = btn.center;//找到btn中心点记录下来
    point = [self.tableView convertPoint:point fromView:btn.superview];
    NSIndexPath* indexpath = [self.tableView indexPathForRowAtPoint:point];
    NSDictionary *dict = self.dataArr[indexpath.row];
    self.curentIndexPath = indexpath;
    self.selectedTypeView = [[SelectedImagUpDataImagView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, ScreenH)ImgStr:dict[@"ballbackImag"]];
    self.selectedTypeView.selectedType = ^(NSString * _Nonnull isTakeAPhoto) {
        if ([isTakeAPhoto isEqualToString:@"1"]) {
//            NSLog(@"拍照");
            [weakSelf checkCameraPermission];
        }else if ([isTakeAPhoto isEqualToString:@"2"]){
//            NSLog(@"相册");
            [weakSelf pushPhotoViewEvent];
           
        }else{
            NSLog(@"取消");
        }
        [weakSelf.selectedTypeView removeFromSuperview];
    };
    [[UIApplication sharedApplication].keyWindow addSubview:self.selectedTypeView];
}
- (void)pushPhotoViewEvent {
    
    [SystemPermissionsToolObject determineLatestPermissionsOfTheLocalAlbum];
    
    TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 columnNumber:4 delegate:self pushPhotoPickerVc:YES];
    imagePickerVc.allowPickingVideo = NO;
    [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
        
        NSArray *imgArr = [NSArray array];
        
        imgArr = photos;
        
        NSString *uploadUrl = CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-tps-api",[ReAddressDynamic shared].baseUrl], FILE_UPLOAD);

        
        [HTTPManager postUploadFiles:uploadUrl file:imgArr fileName:@"file" withVC:self netName:@"文件上传" success:^(id response, NSString *msg) {
            NSMutableDictionary *dic = self.dataArr[_curentIndexPath.row];
            dic[@"imgURL"] = response[@"data"];
            [self OCRNetworking:response[@"data"]];
//            [self.tableView reloadData];
            
        } failure:^(NSInteger code, NSString *msg) {
            
        }];
        
    }];
    imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:imagePickerVc animated:YES completion:nil];
}

#pragma mark - Camera(检查相机权限方法)
- (void)checkCameraPermission {
    AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if (status == AVAuthorizationStatusNotDetermined) {
        [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
            if (granted) {
                [self takePhoto];
            }
        }];
    } else if (status == AVAuthorizationStatusDenied || status == AVAuthorizationStatusRestricted) {
        
        [self alertAlbum];//如果没有权限给出提示
    } else {
        [self takePhoto];//有权限进入调起相机方法
    }
}
- (void)takePhoto {
#pragma mark - 07.判断相机是否可用，如果可用调起
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
        dispatch_async(dispatch_get_main_queue(), ^{
            [self presentViewController:self.imagePickerController animated:YES completion:^{
                
            }];
        });
        
    } else {//不可用只能GG了
        NSLog(@"没有相机");
    }
}
#pragma mark - Album(相册流程与相机流程相同,相册是不存在硬件问题的,只要有权限就可以直接调用)
- (void)checkAlbumPermission {
    PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
    if (status == PHAuthorizationStatusNotDetermined) {
        [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
            dispatch_async(dispatch_get_main_queue(), ^{
                if (status == PHAuthorizationStatusAuthorized) {
                    [self selectAlbum];
                }
            });
        }];
    } else if (status == PHAuthorizationStatusDenied || status == PHAuthorizationStatusRestricted) {
        [self alertAlbum];
    } else {
        [self selectAlbum];
    }
}
- (void)selectAlbum {
    //判断相册是否可用
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
        self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentViewController:self.imagePickerController animated:YES completion:^{
            
        }];
    }
}

- (void)alertAlbum {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"请在设置中打开相册" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        [self dismissViewControllerAnimated:YES completion:nil];
    }];
    [alert addAction:cancel];
    [self presentViewController:alert animated:YES completion:nil];
}
#pragma mark - 03.懒加载初始化弹框;
- (UIImagePickerController *)imagePickerController {
    if (_imagePickerController == nil) {
        _imagePickerController = [[UIImagePickerController alloc] init];
        _imagePickerController.modalPresentationStyle = UIModalPresentationFullScreen;
        _imagePickerController.delegate = self; //delegate遵循了两个代理
        _imagePickerController.allowsEditing = YES;
        _imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
    }
    return _imagePickerController;
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info{
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    NSMutableArray *arr = [NSMutableArray array];
    [arr addObject:image];
    NSString *uploadUrl = CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-tps-api",[ReAddressDynamic shared].baseUrl], FILE_UPLOAD);

    [HTTPManager postUploadFiles:uploadUrl file:arr fileName:@"file" withVC:self netName:@"文件上传" success:^(id response, NSString *msg) {
        NSMutableDictionary *dic = self.dataArr[_curentIndexPath.row];
        dic[@"imgURL"] = response[@"data"];
        [self OCRNetworking:response[@"data"]];
        [self.imagePickerController dismissViewControllerAnimated:YES completion:^{
                    
                }];
//        [self.tableView reloadSection:self.curentIndexPath.section withRowAnimation:(UITableViewRowAnimationNone)];
    } failure:^(NSInteger code, NSString *msg) {
        
    }];
}
- (void)OCRNetworking:(NSString *)string{
    NSMutableDictionary *di = self.dataArr[self.curentIndexPath.row];
    NSDictionary *parmas;
    if ([di[@"title"] isEqualToString:@"挂车行驶证正页上传"]) {
        parmas  = @{
            @"image": string,
            @"ocrType": @"5",
            @"token":[UserDefaultUtil valueForKey:USER_TOKEN],
        };
    }else if([di[@"title"] isEqualToString:@"挂车行驶证副页上传"]){
        parmas = @{
            @"image": string,
            @"ocrType": @"11",
            @"token":[UserDefaultUtil valueForKey:USER_TOKEN],
        };
    }else if([di[@"title"] isEqualToString:@"挂车道路运输证上传"]){
        parmas = @{
            @"image": string,
            @"ocrType": @"7",
            @"token":[UserDefaultUtil valueForKey:USER_TOKEN],
        };
        di[@"upType"] = @"0";
        for (NSInteger i = self.dataArr.count - 1; i >= 0; i--) {
            NSDictionary *dic = self.dataArr[i];
            if ([dic[@"title"] isEqualToString:@"挂车道路运输证号"] || [dic[@"title"] isEqualToString:@"挂车道路运输经营许可号"] || [dic[@"title"] isEqualToString:@"挂车道路运输经证到期日期"]) {
                [self.dataArr removeObjectAtIndex:i];
            }
        }
    }else if([di[@"title"] isEqualToString:@"挂车道路运输证年审凭证上传"]){
        di[@"upType"] = @"1";
        [self.tableView reloadData];
        return;
    }
    [HTTPManager jsonNetworkRequestWithMethod:@"POST" urlString:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-tps-api",[ReAddressDynamic shared].baseUrl], NTOCC_OCRCARD) withParameter:parmas withVC:self netName:@"OCR识别" success:^(id response, NSString *msg) {
        [XSInfoView showInfo:msg onView:self.view];
        if ([di[@"title"] isEqualToString:@"挂车行驶证正页上传"]) {
            [self.gcxszZDic addEntriesFromDictionary:response];
            self.gccpStr = response[@"frontInfo"][@"plateNo"];
//            if ([di[@"upType"] isEqualToString:@"0"]) {
//                NSMutableDictionary *dic2 = [NSMutableDictionary dictionary];
//                [dic2 setValue:@"挂车牌照" forKey:@"title"];
//                [dic2 setValue:self.gccpStr forKey:@"textContent"];
//                [dic2 setValue:@"0" forKey:@"isImagType"];
//                [self.dataArr addObject:dic2];
//            }
        }else if ([di[@"title"] isEqualToString:@"挂车行驶证副页上传"]) {
            [self.gcxszFDic addEntriesFromDictionary:response];
         
        }else if ([di[@"title"] isEqualToString:@"挂车道路运输证上传"]) {
            [self.gcyszDic addEntriesFromDictionary:response];
            if (response[@"经营许可证号"]) {
                self.dlyszhStr = response[@"经营许可证号"];
            }

            if (response[@"证字号"]) {
                self.dlysxkzStr = response[@"证字号"];
            }
            if (response[@"有效期限"]) {
                self.dlysTimeStr = response[@"有效期限"];
            }
            if (response[@"有效期至"]) {
                self.dlysTimeStr = response[@"有效期至"];
            }
            if ([di[@"upType"] isEqualToString:@"0"]) {
//                NSMutableDictionary *dic2 = [NSMutableDictionary dictionary];
//                [dic2 setValue:@"挂车道路运输证号" forKey:@"title"];
//                [dic2 setValue:self.dlyszhStr forKey:@"textContent"];
//                [dic2 setValue:@"0" forKey:@"isImagType"];
//                NSMutableDictionary *dic1 = [NSMutableDictionary dictionary];
//                [dic1 setValue:@"挂车道路运输经营许可号" forKey:@"title"];
//                [dic1 setValue:self.dlysxkzStr forKey:@"textContent"];
//                [dic1 setValue:@"0" forKey:@"isImagType"];
//                NSMutableDictionary *dic3 = [NSMutableDictionary dictionary];
//                [dic3 setValue:@"挂车道路运输经证到期日期" forKey:@"title"];
//                [dic3 setValue:self.dlysTimeStr forKey:@"textContent"];
//                [dic3 setValue:@"0" forKey:@"isImagType"];
//                [self.dataArr addObject:dic2];
//                [self.dataArr addObject:dic1];
//                [self.dataArr addObject:dic3];
            }
            
        }else if ([di[@"title"] isEqualToString:@"挂车道路运输证年审凭证上传"]) {
            //            [self.cyzgzDicTime addEntriesFromDictionary:response];
                    }
        di[@"upType"] = @"1";
        di[@"falseTitle"] = @"";
        di[@"falseCentent"] = @"";
        [self.tableView reloadData];
    } failure:^(NSInteger code, NSString *msg) {
        NSMutableDictionary *dicD = self.dataArr[_curentIndexPath.row];
        dicD[@"upType"] = @"2";
        dicD[@"falseTitle"] = @"识别失败(点击重新上传)";
        dicD[@"falseCentent"] = msg;
        [self.tableView reloadData];
    }];
}
- (NSString *)dicZhuanJsonStr:(NSDictionary *)dic{
    NSError *error;
    if (dic) {
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:0 error:&error];
        if (!jsonData) {
            NSLog(@"Error converting DiC%@",error);
            return @"";
        }else{
            return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
        }
    }else{
        return @"";
    }
    
}
@end
